var mysql = require('mysql');
var connection1 = {};
var connection2 = {};
var connection3 = {};
var connection4 = {};
let host = '116.228.179.13';
let user = 'root';
let password = '5tgb^YHN';
//基础配置数据库begin
connection1.query = function (sqllan, fn) {
    var conn = mysql.createConnection({
        host,
        user,
        password,
        database: 'basicconfiguration'
    });
    conn.connect(function (err) {
        if (err) {
            console.log("connect:: ERROR", err);
            return;
        }
    });
    var sql = sqllan;
    if (!sql) return;
    conn.query(sql, function (err, result, fileds) {
        fn(err, result, fileds)
    });
    conn.end(function (err) {
        if (err) {
            console.log("END:: ERROR", err);
            return;
        } else {
            console.log("链接关闭");
        }
    });
}
//阿米巴数据库begin
connection2.query = function (sqllan, fn) {
    var conn = mysql.createConnection({
        host,
        user,
        password,
        database: 'amiba'
    });
    conn.connect(function (err) {
        if (err) {
            console.log("connect:: ERROR", err);
            return;
        }
    });
    var sql = sqllan;
    if (!sql) return;
    conn.query(sql, function (err, result, fileds) {
        fn(err, result, fileds)
    });
    conn.end(function (err) {
        if (err) {
            console.log("END:: ERROR", err);
            return;
        } else {
            console.log("链接关闭");
        }
    });
}
//股东投票数据库begin
connection3.query = function (sqllan, fn) {
    var conn = mysql.createConnection({
        host,
        user,
        password,
        database: 'basicconfiguration'
    });
    conn.connect(function (err) {
        if (err) {
            console.log("connect:: ERROR", err);
            return;
        }
    });
    var sql = sqllan;
    if (!sql) return;
    conn.query(sql, function (err, result, fileds) {
        fn(err, result, fileds)
    });
    conn.end(function (err) {
        if (err) {
            console.log("END:: ERROR", err);
            return;
        } else {
            console.log("链接关闭");
        }
    });
}
//部门抓取的状态begin
connection4.query = function (sqllan, fn) {
    var conn = mysql.createConnection({
        host,
        user,
        password,
        database: 'name'
    });
    conn.connect(function (err) {
        if (err) {
            console.log("connect:: ERROR", err);
            return;
        }
    });
    var sql = sqllan;
    if (!sql) return;
    conn.query(sql, function (err, result, fileds) {
        fn(err, result, fileds)
    });
    conn.end(function (err) {
        if (err) {
            console.log("END:: ERROR", err);
            return;
        } else {
            console.log("链接关闭");
        }
    });
}

module.exports = {
    connection1,
    connection2,
    connection3,
    connection4
};
